<?php
include_once(_CORE_PATH. 'router/router_prototype.php');
class router_media_http extends router_prototype
{
	public function DetectCtrlAndAction(array $elements = array())
	{
		$ctrlName = $actionName = '';

		$styleExtensions = MozgCfg::GetProp('global//styleExtensions');
        $mediaExtensions = MozgCfg::GetProp('global//mediaFilesExtensions');
         
        $path = $elements['path'];
        if (sizeof($styleExtensions) && preg_match('#\.(' .implode(array_map('preg_quote', $styleExtensions), '|'). ')$#is', $path)) 
        {
            $ctrlName = 'style';
        }
        elseif (sizeof($mediaExtensions) && preg_match('#\.(' .implode(array_map('preg_quote', $mediaExtensions), '|'). ')$#is', $path))
        {
        	$ctrlName = 'image';         
        }		
		
		return array($ctrlName, $actionName);
	}

	/**
	 * определяем поведение controller & action
	 * 
	 */
	public function Build(array &$elements = array())
	{
		$url = array();
		
		$url = array(router_http::SKIPENCODEURL.$elements['path']);
		unset($elements['path']);	
		
		return $url;
	}
	
	public function Parse(array &$segments = array())
	{
		$elements = array();

        $elements['path'] = implode('/', array_map('urlencode', $segments));        
        $segments = array();
        
		return $elements;
	}
}